home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / anlogclk / reqfiles / rot8shp.sx
Encoding:
Text File  |  1996-05-21  |  2.1 KB  |  68 lines  |  [TEXT/ttxt]

  1. in module AnalogClockModule
  2.  
  3. class RotatingShape (TwoDPresenter)
  4. instance variables
  5.     rotMatrix
  6.     workMatrix
  7.     xDiff
  8.     yDiff
  9.     fill
  10.     stroke
  11. end
  12. method draw self {class RotatingShape} theSurface theClip ->
  13. (
  14.     nextMethod self theSurface theClip
  15.     local workMatrix := self.workMatrix
  16.     setTo workMatrix self.rotMatrix
  17.     translate workMatrix (self.x + self.xDiff) (self.y + self.yDiff)
  18.     if (self.fill <> undefined) do
  19.         fill theSurface self.target theClip workMatrix self.fill
  20.     if (self.stroke <> undefined) do
  21.         stroke theSurface self.target theClip workMatrix self.stroke
  22.     -- For debugging only - check the boundary.
  23.     -- stroke theSurface self.boundary theClip self.globalTransform blackBrush
  24.     self
  25. )
  26. method rotate self {class RotatingShape} amount units ->
  27. (
  28.     rotate self.rotMatrix amount units
  29.     notifyChanged self false
  30. )
  31. method init self {class RotatingShape} #rest args #key \
  32.     fill:(undefined) stroke:(undefined) \
  33.     axisPos:(new Point x:0 y:0) ->
  34. (
  35.     apply nextMethod self args
  36.     self.fill := fill
  37.     self.stroke := stroke
  38.     self.xDiff := axisPos.x
  39.     self.yDiff := axisPos.y
  40. )
  41. method afterInit self {class RotatingShape} #rest args ->
  42. (
  43.     apply nextMethod self args
  44.     if ((self.fill = undefined) and (isAKindOf self.target Bitmap)) do
  45.         self.fill := defaultBrush
  46.     self.workMatrix := mutableCopy identityMatrix
  47.     -- Rotation is always around [0,0].
  48.     self.rotMatrix := translate (mutableCopy identityMatrix) \
  49.         (-self.xDiff) (-self.yDiff)
  50.     -- The largest box needed to contain the rotation
  51.     -- has sides twice the length of the maximum diagonal
  52.     -- of the rotation.
  53.     local tBbox := transform self.target.bbox self.rotMatrix @create
  54.     local n := (ceiling (sqrt (max \
  55.         ((tBbox.x1 * tBbox.x1) + (tBbox.y1 * tBbox.y1)) \
  56.         ((tBbox.x2 * tBbox.x2) + (tBbox.y2 * tBbox.y2)) \
  57.         ))) * 2
  58.     -- Allow room for a border stroke.  (NOTE: Because this is only 
  59.     -- calcuated during instance creation, you cant change the stroke IV.
  60.     -- This restriction could be removed by specializing strokeSetter.)
  61.     if (self.stroke <> undefined) do
  62.         n := n + (self.stroke.lineWidth * 2)
  63.     self.boundary := new Rect x1:(self.xDiff - n/2) x2:(self.xDiff + n/2) \
  64.         y1:(self.yDiff - n/2) y2:(self.yDiff + n/2)
  65. )
  66.  
  67. "Loaded rot8shp.sx"
  68.